﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace WMM.Tapioca.Linkbase
{
    /// <summary>
    /// XBRL 2.1 Specification 3.5.3.8
    /// A resource is an XML fragment in an extended link that is related to other resources in the extended link 
    /// and to resources outside of the extended link.
    /// </summary>
    public class Resource : ExtendedLinkElement
    {
        private string lang;

        private string content;

        private XElement resourceXElement;

        /// <returns> XElement of this resource. </returns>
        public XElement ResourceXElement
        {
            get { return resourceXElement; }
            set { resourceXElement = value; }
        }

        /// <returns> xml:lang attribute of this resource. </returns>
        public virtual string Lang
        {
            get
            {
                return lang;
            }
            set
            {
                lang = value;
            }
        }



        /// <returns> Content of this resource (value of the according XML element). </returns>
        public virtual string Content
        {
            get
            {
                return content;
            }
            set
            {
                content = value;
            }
        }

        private ExtendedLink extendedLinkParent;

        /// <summary>
        /// The Extended Link Parent of arc.
        /// </summary>
        public ExtendedLink ExtendedLinkParent
        {
            get { return extendedLinkParent; }
            set { extendedLinkParent = value; }
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="element">
        ///            XElement of this resource. </param>
        /// <param name="label">
        ///            Label of this resource. </param>
        /// <param name="documentSource">
        ///            Linkbase Source for this extended link element. </param>
        /// <param name="extendedLink">
        ///            The extended link this resource. </param>
        public Resource(XElement element, string label, string documentSource, ExtendedLink extendedLink)
            : base(label, documentSource)
        {
            extendedLinkParent = extendedLink;
            this.resourceXElement = element;
            this.LocalName = element.Name.LocalName;
            this.NamespaceUri = element.Name.NamespaceName;
            this.Id = "";
            this.Content = element.Value;
        }

        /// <returns> false </returns>
        public override bool IsLocator()
        {
            return false;
        }

        /// <returns> true </returns>
        public override bool IsResource()
        {
            return true;
        }
    }
}
